package com.lanju.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanju.common.SpringUtils;
import com.lanju.entity.User;
import com.lanju.service.AuthService;
import com.lanju.service.UserService;

@Controller
@RequestMapping("auth")
public class AuthController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(AuthController.class);
	
	@Autowired
	AuthService authService;
	 @Autowired
	 UserService userService;
	
	@SuppressWarnings("unchecked")
	@RequestMapping("toAuth")
	@ResponseBody
	public Map<String,Object> toAuth(HttpServletRequest request,HttpSession session){
		Map<String, Object>  param = SpringUtils.getParameterMap(request);
		Map<String, Object> result = null;
		try {
			result = authService.toAuth(param);
			User user =(User) session.getAttribute("userModel");
			User u=userService.getById(user.getUserId());
			session.setAttribute("userModel", u);
		} catch (Exception e) {
			e.printStackTrace();
			result.put("success", false);
		}
		return result;
	}
}
